home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / LgcyPlus / disk2 / HAMMER._ / HAMMER.
Encoding:
Text File  |  2001-03-02  |  2.9 KB  |  78 lines

  1. 10    ! *********************************************************************
  2. 20    ! Example: Hammer Game
  3. 30    !
  4. 40    ! The object of this game is to click the pushbutton before it moves.
  5. 50    ! How often the button moves and how large it is are adjustable with
  6. 60    ! sliders. Every time the button is successfully clicked, the score
  7. 70    ! increases by one point.
  8. 80    !
  9. 90    ! *********************************************************************
  10. 100   !
  11. 110   ! Move the button every two seconds
  12. 120   !
  13. 130   Speed=2
  14. 140   ASSIGN @Speed TO WIDGET "SLIDER";SET ("ORIENTATION":"HORIZONTAL","X":415,"Y":10,"TITLE":" Speed ","LOGARITHMIC":1,"VALUE":Speed,"WIDTH":250,"HEIGHT":60)
  15. 150   CONTROL @Speed;SET ("MAXIMUM":2,"MINIMUM":.2)
  16. 160   ON EVENT @Speed,"DONE",3 GOSUB Speed_change
  17. 170   !
  18. 180   ! Set button size to 25 pixels on a side
  19. 190   !
  20. 200   Size=25
  21. 210   ASSIGN @Size TO WIDGET "SLIDER";SET ("ORIENTATION":"HORIZONTAL","X":150,"Y":10,"TITLE":" Size ","LOGARITHMIC":1,"VALUE":Size,"WIDTH":250,"HEIGHT":60)
  22. 220   CONTROL @Size;SET ("MAXIMUM":100,"MINIMUM":10)
  23. 230   ON EVENT @Size,"DONE",3 GOSUB Size_change
  24. 240   !
  25. 250   ! Set up the score
  26. 260   !
  27. 270   Score=0
  28. 280   ASSIGN @Score TO WIDGET "LABEL";SET ("VALUE":VAL$(Score),"TITLE":" Hits","X":10,"Y":10,"WIDTH":125,"HEIGHT":60)
  29. 290   !
  30. 300   ! Draw the moving widget
  31. 310   !
  32. 320   ASSIGN @Button TO WIDGET "PUSHBUTTON";SET ("WIDTH":50,"HEIGHT":30,"LABEL":"","TITLE":"","X":300)
  33. 330   !
  34. 340   ! When the button is pushed, score a hit
  35. 350   !
  36. 360   ON EVENT @Button,"ACTIVATED",3 GOSUB Hit
  37. 370   !
  38. 380   ! Provide a button to stop the game
  39. 390   !
  40. 400   ASSIGN @Stop TO WIDGET "PUSHBUTTON";SET ("RESIZABLE":0,"WIDTH":125,"HEIGHT":30,"LABEL":"Quit","TITLE":"","X":10,"Y":80)
  41. 410   ON EVENT @Stop,"ACTIVATED",3 GOTO Stop_game
  42. 420   !
  43. 430   ! Move the button on a regular basis
  44. 440   !
  45. 450   ON CYCLE Speed GOSUB Move_button
  46. 460   LOOP
  47. 470     WAIT FOR EVENT
  48. 480   END LOOP
  49. 490 Hit:                    ! Button was hit
  50. 500   Score=Score+1
  51. 510   CONTROL @Score;SET ("VALUE":VAL$(Score))
  52. 520   GOSUB Move_button     ! Too easy to hit again
  53. 530   RETURN
  54. 540 Move_button:            ! Move the button to new location
  55. 550   !         
  56. 560   ! The scaling should depend on the size of the display
  57. 570   !
  58. 580   CONTROL @Button;SET ("X":RND*500+60,"Y":RND*400)
  59. 590   RETURN
  60. 600 Speed_change:                  ! Speed slider was moved
  61. 610   !                           
  62. 620   STATUS @Speed;RETURN ("VALUE":Speed)
  63. 630   ON CYCLE Speed GOSUB Move_button
  64. 640   RETURN
  65. 650 Size_change:                   ! Size slider was moved
  66. 660   STATUS @Size;RETURN ("VALUE":Size)
  67. 670   CONTROL @Button;SET ("WIDTH":Size,"HEIGHT":Size)
  68. 680   RETURN
  69. 690 Stop_game:  !
  70. 700   OFF CYCLE
  71. 710   ASSIGN @Button TO *
  72. 720   ASSIGN @Size TO *
  73. 730   ASSIGN @Speed TO *
  74. 740   ASSIGN @Score TO *
  75. 750   ASSIGN @Stop TO *
  76. 760   STOP
  77. 770   END
  78.